package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Team;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/27.
 */

public class BatchAddTeamAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    public List<Team> teamList;
    private OnDeleteClickListener onDeleteClickListener;

    public BatchAddTeamAdapter(Context context, List<Team> teamList) {
        this.inflater = LayoutInflater.from(context);
        this.teamList = teamList;
    }

    public void setTeamList(List<Team> teamList) {
        this.teamList = teamList;
        notifyDataSetChanged();
    }

    public void setOnDeleteClickListener(OnDeleteClickListener onDeleteClickListener) {
        this.onDeleteClickListener = onDeleteClickListener;
    }

    @Override
    public int getCount() {
        return teamList.size();
    }

    @Override
    public Object getItem(int position) {
        return teamList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = inflater.inflate(R.layout.item_add_group, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Team team = teamList.get(position);
        holder.teamTv.setText(team.getName());
        holder.delTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDeleteClickListener.onClick(position);
            }
        });
        return convertView;
    }

    public interface OnDeleteClickListener{
        void onClick(int posision);
    }

    static class ViewHolder {
        @BindView(R.id.team_tv)
        HXTextView teamTv;
        @BindView(R.id.del_tv)
        RelativeLayout delTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
